package com.project.service.Imp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.MailBean;
import com.project.mapper.IMailMapper;
import com.project.service.IMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.Arrays;

@Service
public class MailService implements IMailService {
    @Autowired
    private IMailMapper mailMapper;

    @Override
    public void addEmail(MailBean mail, Integer[] userArray, String[] userNameArray) {
        String str = Arrays.toString(userNameArray);
        str = str.substring(1, str.length() - 1);
        System.out.println(str+"+++++++++++++");
        mailMapper.addEmail(mail,str);
        mailMapper.addBox(userArray,mail.getMailId());


    }

    @Override
    public PageInfo<MailBean> findByItem(Integer pageNo, Integer userId, String title, LocalDate startDate, LocalDate endDate) {
        PageHelper.startPage(pageNo, 2);
        PageInfo<MailBean> of = PageInfo.of(mailMapper.findByItem(userId, title, startDate, endDate));
        return of;
    }

    @Override
    public MailBean findById(Integer id) {

        return mailMapper.findById(id);
    }

    @Override
    public void delMail(Integer id) {
        mailMapper.delMail(id);
    }
}
